package com.gopay.bis.tbank.ebank.impl;

import java.util.HashMap;
import java.util.Map;

import com.gopay.bis.common.util.BankLogUtils;
import com.gopay.bis.tbank.ebank.operation.TBankB2bQuery;
import com.gopay.common.domain.bank.BaseMessage;
import com.gopay.common.domain.bank.tbank.ebank.pay.TBankMessage;
import com.gopay.common.domain.bank.tbank.ebank.query.req.TBankOrderReq;
import com.gopay.common.domain.bank.tbank.ebank.query.res.TBankOrderRes;
import com.gopay.common.exception.GopayException;
import com.gopay.remote.bank.businesses.BankService;

/**
 * 电子银行业务请求接口
 * 
 * @TBankB2bBankServiceImpl.java
 * @author WangHongFei
 */
public class TBankB2bBankServiceImpl implements BankService{
	
	private TBankB2bQuery tbankB2bQuery;
	 
	public String sign(BaseMessage message) throws GopayException{
		TBankMessage messageB2B = (TBankMessage) message;
		BankLogUtils.printB2BSignPlainLog(messageB2B);
		BankLogUtils.printB2BSignSignatureLog(messageB2B, messageB2B.getSignMessage());
		return messageB2B.getSignMessage();
	}

	public Object verify(BaseMessage message) throws GopayException{
		TBankMessage messageB2B = (TBankMessage) message;
		BankLogUtils.printB2BVerifyPlainLog(messageB2B);;
		BankLogUtils.printB2BVerifySignatureLog(messageB2B);;
		return true;
	}
	
	public Object query(Object object) throws GopayException {
		TBankOrderReq req = (TBankOrderReq) object;
		Map<String, String> map = new HashMap<String, String>();
		map.put("orderNo", req.getOrderNo());
		map.put("mercNo", req.getMercNo());
		map.put("msgType", req.getMsgType());
		map.put("txnType", req.getTxnType());
		map.put("signDate", req.getSignDate());
		TBankOrderRes resMessage = new TBankOrderRes();
		Object messageData = tbankB2bQuery.submit(map,req.getBankUrl());
		resMessage = tbankB2bQuery.parse(messageData);
		return resMessage;
	}
	
	public void setTbankB2bQuery(TBankB2bQuery tbankB2bQuery) {
		this.tbankB2bQuery = tbankB2bQuery;
	}

	@Override
	public Object dayend(Object obj) throws GopayException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object refund(Object obj) throws GopayException {
		// TODO Auto-generated method stub
		return null;
	}

}